package com.example.team.controller;

import com.example.team.entity.Menu;
import com.example.team.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：代志雄
 * 2023年11月3日11点35分
 */
@RestController
@Api(tags = "菜单管理")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    @ApiOperation(value = "添加菜单信息",
            notes = "成功返回1")
    @RequestMapping(value="/insertMenu",method = {RequestMethod.GET})
    public int insertMenu(Menu menu){
        return menuService.insertMenu(menu);
    }

    @ApiOperation(value = "删除菜单信息",
            notes = "成功返回1")
    @RequestMapping(value="/deleteMenu",method = {RequestMethod.GET})
    public int deleteMenu(int id){
        Menu menu=new Menu();
        menu.setMenuId(id);
        return menuService.deleteMenu(menu);
    }

    @ApiOperation(value = "修改菜单信息",
            notes = "成功返回1")
    @RequestMapping(value="/updateMenu",method = {RequestMethod.GET})
    public int updateMenu(Menu menu){
        return menuService.updateMenu(menu);
    }

    @ApiOperation(value = "查询所有菜单信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getAllMenu",method = {RequestMethod.GET})
    public List<Menu> getAllMenu(String name){
        Menu menu=new Menu();
        menu.setMenuName(name);
        return menuService.getAllMenu(menu);
    }

    @ApiOperation(value = "查询菜单信息",
            notes = "成功返回Json")
    @RequestMapping(value="/getMenu",method = {RequestMethod.GET})
    public Menu getMenu(String name){
        Menu menu=new Menu();
        menu.setMenuName(name);
        return menuService.getMenu(menu);
    }
}